/**
 * 作者: hxl
 * 日期: 2025-07-08 10:27:43
 * 备注: 用户联盟乱斗信息表（永驻活动）
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserUnionScuffleInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserUnionScuffleInfoWeekModel extends BaseModel implements Model {
    public static final String LISTKEY = "";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 玩家id
    protected long enemyUnionId; // 当前匹配对手联盟id
    protected int videoWatch; // 广告恢复次数
    protected int energy; // 体力
    protected long energyRecoverTime; // 上次恢复体力时间
    protected long dayResetTime; // 每日重置时间
    protected long score; // 个人积分
    protected int singleRankReward; // 个人排行榜奖励
    protected int unionRankReward; // 联盟排行榜奖励
    protected long weekResetTime; // 每周重置时间
    protected byte buyHigh; // 是否购买进阶礼包
    protected byte buySpecial; // 是否购买专项礼包
    protected int beatNum; // 打败敌人数
    protected int normalPassReward; // 已领取的通行证普通奖励
    protected int highPassRewad; // 已领取的通行证进阶奖励
    protected int specialPassReward; // 已领取的通行证专项奖励

    public void reset() {
    }

    protected String getKey() {
        return "UserUnionScuffleInfoWeek." + id;
    }

    protected String getListKey() {
        return null;
    }

    protected String getListItemKey() {
        return null;
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_union_scuffle_info_week"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 玩家id
        obj.put("enemyUnionId", enemyUnionId); // 当前匹配对手联盟id
        obj.put("videoWatch", videoWatch); // 广告恢复次数
        obj.put("energy", energy); // 体力
        obj.put("energyRecoverTime", energyRecoverTime); // 上次恢复体力时间
        obj.put("dayResetTime", dayResetTime); // 每日重置时间
        obj.put("score", score); // 个人积分
        obj.put("singleRankReward", singleRankReward); // 个人排行榜奖励
        obj.put("unionRankReward", unionRankReward); // 联盟排行榜奖励
        obj.put("weekResetTime", weekResetTime); // 每周重置时间
        obj.put("buyHigh", buyHigh); // 是否购买进阶礼包
        obj.put("buySpecial", buySpecial); // 是否购买专项礼包
        obj.put("beatNum", beatNum); // 打败敌人数
        obj.put("normalPassReward", normalPassReward); // 已领取的通行证普通奖励
        obj.put("highPassRewad", highPassRewad); // 已领取的通行证进阶奖励
        obj.put("specialPassReward", specialPassReward); // 已领取的通行证专项奖励
        return obj;
    }

    public PBUserUnionScuffleInfo.Builder takeInitBuilder() {
        PBUserUnionScuffleInfo.Builder sb = PBUserUnionScuffleInfo.newBuilder();
        if (videoWatch != 0) {
            sb.setVideoWatch(videoWatch);
        }
        if (energy != 0) {
            sb.setEnergy(energy);
        }
        if (energyRecoverTime != 0) {
            sb.setEnergyRecoverTime(energyRecoverTime);
        }
        if (score != 0) {
            sb.setScore(score);
        }
        if (singleRankReward != 0) {
            sb.setSingleRankReward(singleRankReward);
        }
        if (unionRankReward != 0) {
            sb.setUnionRankReward(unionRankReward);
        }
        if (buyHigh != 0) {
            sb.setBuyHighGift(true);
        }
        if (buySpecial != 0) {
            sb.setBuySpecialGift(true);
        }
        if (beatNum != 0) {
            sb.setBeatNum(beatNum);
        }
        if (normalPassReward != 0) {
            sb.setNormalPassReward(normalPassReward);
        }
        if (highPassRewad != 0) {
            sb.setHighPassRewad(highPassRewad);
        }
        if (specialPassReward != 0) {
            sb.setSpecialPassReward(specialPassReward);
        }
        return sb;
    }

    public PBUserUnionScuffleInfo.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserUnionScuffleInfo.Builder sb = PBUserUnionScuffleInfo.newBuilder();
        if (isFieldUpdate("videoWatch")) {
            sb.setVideoWatch(videoWatch);
        }
        if (isFieldUpdate("energy")) {
            sb.setEnergy(energy);
        }
        if (isFieldUpdate("energyRecoverTime")) {
            sb.setEnergyRecoverTime(energyRecoverTime);
        }
        if (isFieldUpdate("score")) {
            sb.setScore(score);
        }
        if (isFieldUpdate("singleRankReward")) {
            sb.setSingleRankReward(singleRankReward);
        }
        if (isFieldUpdate("unionRankReward")) {
            sb.setUnionRankReward(unionRankReward);
        }
        if (isFieldUpdate("buyHigh")) {
            sb.setBuyHighGift(buyHigh > 0);
        }
        if (isFieldUpdate("buySpecial")) {
            sb.setBuySpecialGift(buySpecial > 0);
        }
        if (isFieldUpdate("beatNum")) {
            sb.setBeatNum(beatNum);
        }
        if (isFieldUpdate("normalPassReward")) {
            sb.setNormalPassReward(normalPassReward);
        }
        if (isFieldUpdate("highPassRewad")) {
            sb.setHighPassRewad(highPassRewad);
        }
        if (isFieldUpdate("specialPassReward")) {
            sb.setSpecialPassReward(specialPassReward);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getEnemyUnionId() {
        return enemyUnionId;
    }

    public void putEnemyUnionId(long enemyUnionId) {
        if (this.enemyUnionId != enemyUnionId) {
            this.enemyUnionId = enemyUnionId;
            updateRedisHashField(getKey(), "enemyUnionId", this.enemyUnionId);
        }
    }

    public void addEnemyUnionId(long value) {
        this.enemyUnionId += value;
        updateRedisHashField(getKey(), "enemyUnionId", this.enemyUnionId);
    }

    public int getVideoWatch() {
        return videoWatch;
    }

    public void putVideoWatch(int videoWatch) {
        if (this.videoWatch != videoWatch) {
            this.videoWatch = videoWatch;
            updateRedisHashField(getKey(), "videoWatch", this.videoWatch);
        }
    }

    public void addVideoWatch(int value) {
        this.videoWatch += value;
        updateRedisHashField(getKey(), "videoWatch", this.videoWatch);
    }

    public int getEnergy() {
        return energy;
    }

    public void putEnergy(int energy) {
        if (this.energy != energy) {
            this.energy = energy;
            updateRedisHashField(getKey(), "energy", this.energy);
        }
    }

    public void addEnergy(int value) {
        this.energy += value;
        updateRedisHashField(getKey(), "energy", this.energy);
    }

    public long getEnergyRecoverTime() {
        return energyRecoverTime;
    }

    public void putEnergyRecoverTime(long energyRecoverTime) {
        if (this.energyRecoverTime != energyRecoverTime) {
            this.energyRecoverTime = energyRecoverTime;
            updateRedisHashField(getKey(), "energyRecoverTime", this.energyRecoverTime);
        }
    }

    public void addEnergyRecoverTime(long value) {
        this.energyRecoverTime += value;
        updateRedisHashField(getKey(), "energyRecoverTime", this.energyRecoverTime);
    }

    public long getDayResetTime() {
        return dayResetTime;
    }

    public void putDayResetTime(long dayResetTime) {
        if (this.dayResetTime != dayResetTime) {
            this.dayResetTime = dayResetTime;
            updateRedisHashField(getKey(), "dayResetTime", this.dayResetTime);
        }
    }

    public void addDayResetTime(long value) {
        this.dayResetTime += value;
        updateRedisHashField(getKey(), "dayResetTime", this.dayResetTime);
    }

    public long getScore() {
        return score;
    }

    public void putScore(long score) {
        if (this.score != score) {
            this.score = score;
            updateRedisHashField(getKey(), "score", this.score);
        }
    }

    public void addScore(long value) {
        this.score += value;
        updateRedisHashField(getKey(), "score", this.score);
    }

    public int getSingleRankReward() {
        return singleRankReward;
    }

    public void putSingleRankReward(int singleRankReward) {
        if (this.singleRankReward != singleRankReward) {
            this.singleRankReward = singleRankReward;
            updateRedisHashField(getKey(), "singleRankReward", this.singleRankReward);
        }
    }

    public void addSingleRankReward(int value) {
        this.singleRankReward += value;
        updateRedisHashField(getKey(), "singleRankReward", this.singleRankReward);
    }

    public int getUnionRankReward() {
        return unionRankReward;
    }

    public void putUnionRankReward(int unionRankReward) {
        if (this.unionRankReward != unionRankReward) {
            this.unionRankReward = unionRankReward;
            updateRedisHashField(getKey(), "unionRankReward", this.unionRankReward);
        }
    }

    public void addUnionRankReward(int value) {
        this.unionRankReward += value;
        updateRedisHashField(getKey(), "unionRankReward", this.unionRankReward);
    }

    public long getWeekResetTime() {
        return weekResetTime;
    }

    public void putWeekResetTime(long weekResetTime) {
        if (this.weekResetTime != weekResetTime) {
            this.weekResetTime = weekResetTime;
            updateRedisHashField(getKey(), "weekResetTime", this.weekResetTime);
        }
    }

    public void addWeekResetTime(long value) {
        this.weekResetTime += value;
        updateRedisHashField(getKey(), "weekResetTime", this.weekResetTime);
    }

    public byte getBuyHigh() {
        return buyHigh;
    }

    public void putBuyHigh(byte buyHigh) {
        if (this.buyHigh != buyHigh) {
            this.buyHigh = buyHigh;
            updateRedisHashField(getKey(), "buyHigh", this.buyHigh);
        }
    }

    public void addBuyHigh(byte value) {
        this.buyHigh += value;
        updateRedisHashField(getKey(), "buyHigh", this.buyHigh);
    }

    public byte getBuySpecial() {
        return buySpecial;
    }

    public void putBuySpecial(byte buySpecial) {
        if (this.buySpecial != buySpecial) {
            this.buySpecial = buySpecial;
            updateRedisHashField(getKey(), "buySpecial", this.buySpecial);
        }
    }

    public void addBuySpecial(byte value) {
        this.buySpecial += value;
        updateRedisHashField(getKey(), "buySpecial", this.buySpecial);
    }

    public int getBeatNum() {
        return beatNum;
    }

    public void putBeatNum(int beatNum) {
        if (this.beatNum != beatNum) {
            this.beatNum = beatNum;
            updateRedisHashField(getKey(), "beatNum", this.beatNum);
        }
    }

    public void addBeatNum(int value) {
        this.beatNum += value;
        updateRedisHashField(getKey(), "beatNum", this.beatNum);
    }

    public int getNormalPassReward() {
        return normalPassReward;
    }

    public void putNormalPassReward(int normalPassReward) {
        if (this.normalPassReward != normalPassReward) {
            this.normalPassReward = normalPassReward;
            updateRedisHashField(getKey(), "normalPassReward", this.normalPassReward);
        }
    }

    public void addNormalPassReward(int value) {
        this.normalPassReward += value;
        updateRedisHashField(getKey(), "normalPassReward", this.normalPassReward);
    }

    public int getHighPassRewad() {
        return highPassRewad;
    }

    public void putHighPassRewad(int highPassRewad) {
        if (this.highPassRewad != highPassRewad) {
            this.highPassRewad = highPassRewad;
            updateRedisHashField(getKey(), "highPassRewad", this.highPassRewad);
        }
    }

    public void addHighPassRewad(int value) {
        this.highPassRewad += value;
        updateRedisHashField(getKey(), "highPassRewad", this.highPassRewad);
    }

    public int getSpecialPassReward() {
        return specialPassReward;
    }

    public void putSpecialPassReward(int specialPassReward) {
        if (this.specialPassReward != specialPassReward) {
            this.specialPassReward = specialPassReward;
            updateRedisHashField(getKey(), "specialPassReward", this.specialPassReward);
        }
    }

    public void addSpecialPassReward(int value) {
        this.specialPassReward += value;
        updateRedisHashField(getKey(), "specialPassReward", this.specialPassReward);
    }

}